﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.Domain;
using RBAC.Domain.Service.Interfae;

namespace RBACDuYaJun.Api.Controllers
{
    /// <summary>
    /// 角色与菜单的关系管理
    /// </summary>
    [Route("api/[controller]/[action]")]
   [Authorize]//（JWT）
    [ApiController]
    public class RoleMenuController : ControllerBase
    {
        private readonly IRoleMenuService _roleMenuService;
        public RoleMenuController(IRoleMenuService roleMenuService)
        {
            _roleMenuService = roleMenuService;
        }
       


        /// <summary>
        /// 角色树形
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Menument>> GetRoleAsync()
        {
            return await _roleMenuService.GetRoleAsync();

        }
        /// <summary>
        ///菜单树形
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Menument>> GetMenuAsync(int rid = 0)
        {
           return await _roleMenuService.GetMenuAsync(rid);
        }
        /// <summary>
        /// 添加角色菜单的关系
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="MenuId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddRoleMenu(int roleId, List<int> MenuId)
        {
           return await _roleMenuService.AddRoleMenu(roleId, MenuId);
        }

        /// <summary>
        /// 根据角色ID反填菜单
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<RoleMenu>> GetMenuValue(int rid)
        {
           return await _roleMenuService.GetMenuValue(rid);
        }

    }
}
